﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackSystem.Contracts;
using TrackSystem.Entities.Models;

namespace TrackSystem.EntityFramework.Repositories
{
    public class AlarmRepository : Repositories<AlarmTable, int>, IAlarmRepository
    {
        private readonly IMapper _mapper;

        public AlarmRepository(TkDBContent dbContent, IMapper mapper) : base(dbContent)
        {
            _mapper = mapper;            
        }

        public int Add(AlarmTable alarmTable)
        {
            int counter = Table.Count(a => a.Identify == alarmTable.Identify);
            if (counter > 0)
            {
                var entity = Table.First(a => a.Identify == alarmTable.Identify);
                entity.HappenDt = alarmTable.HappenDt;
                entity.Counter = alarmTable.Counter;
                entity.Confirm = alarmTable.Confirm;
                entity.ConfirmDt = alarmTable.ConfirmDt;
                Update(entity);
                return 1;
            }

            Insert(alarmTable);
            return 1;
        }
    }
}
